Skip to content

docs: explain hostNetwork port defaulting in C-0044 and C-0204 - #205

Merged
matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:docs/hostnetwork-hostport-defaulting
Dec 2, 2026
Merged

matthyx merged 1 commit into
kubescape:mainfrom
ANAMASGARD:docs/hostnetwork-hostport-defaulting

Conversation

@ANAMASGARD

@ANAMASGARD ANAMASGARD commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #189. Follow-up to #188.

What changed

Explain that Kubernetes defaults an omitted or zero hostPort to containerPort on regular and init containers in host-networked Pods. Both controls deny those port declarations. The pages now clarify that workload templates are evaluated before this Pod-specific default takes effect.

Correct the C-0204 comparison with C-0044. Both policies check init containers and treat zero hostPort the same way. C-0204 also matches pods/ephemeralcontainers updates.

Verification

  • All 41 existing C-0044 and C-0204 admission cases passed on kind with Kubernetes v1.36.1.
  • Server-side dry runs confirmed hostPort defaulting for omitted and explicit-zero values on Pods and for an init container port. The Deployment template's hostPort remained unset.
  • All 8 helper unit tests passed. Both Markdown pages rendered with Pandoc, the new Kubernetes API reference link was verified, and git diff --check passed.

Before and after

Compared the same C-0204 Markdown page on main (4bd6dec) and the rebased PR (2af14b4).

git diff upstream/main...HEAD -- docs/policies-based-on-kubescape-controls/kubescape-c-0204-deny-containers-using-host-ports.md
  • Before: the page said that hostPort: 0 was allowed without distinguishing a host-networked Pod from a workload template.
  • After: the page says that a host-networked Pod defaults an omitted or zero hostPort to its nonzero containerPort, so the policy denies that Pod. A workload template does not receive this Pod-specific default.

On the rebased branch, both updated pages rendered with Pandoc, git diff --check passed, and all 14 test-runner unit tests passed. I did not repeat the Kubernetes admission runs from the original verification after the rebase.

Summary by CodeRabbit

  • Documentation
    • Clarified how the host-port policies handle regular and init containers, host-networked Pods, and Kubernetes defaults for omitted or zero hostPort values.
    • Explained that workload templates may pass policy checks while Pods created from them may be denied when Pod checks also apply.
    • Updated the comparison of the policies, including ephemeral-container checks and requests through pods/ephemeralcontainers.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The C-0044 and C-0204 policy pages now describe hostPort behavior for host-networked Pods, including API-server defaulting and differences between workload-template checks and Pod admission.

Changes: Host port policy documentation

Layer / File(s) Summary
Document hostPort policy behavior
docs/policies-based-on-kubescape-controls/kubescape-c-0044-deny-resources-with-host-port.md, docs/policies-based-on-kubescape-controls/kubescape-c-0204-deny-containers-using-host-ports.md
The pages describe nonzero hostPort checks, init containers, and API-server defaulting for host-networked Pods. They distinguish workload-template checks from Pod admission and document ephemeral-container checks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

Suggested reviewers: matthyx, sanchit2662

Merge Risk: Minimal · up to d61da

This documentation-only change corrects how the C-0044 and C-0204 pages describe hostPort handling for host-networked Pods. It does not alter runtime behavior and has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: documentation for C-0044 and C-0204 now explains that Kubernetes defaults an omitted or zero hostPort to containerPort for host-networked Pods. The raw summary and obj…
Linked Issues check Passed Issue #189 asks for C-0204 docs to stop saying containerPort-only and hostPort: 0 are allowed for host-networked Pods, and to check the C-0044 page. The diff removes the prior claim in the C-0204 page…
Out of Scope Changes check Passed The PR changes only two Markdown policy pages under docs/policies-based-on-kubescape-controls/. Every change concerns hostPort behavior for host-networked Pods, workload templates, or the C-0044/C-020…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: documentation for C-0044 and C-0204 now explains that Kubernetes defaults an omitted or zero hostPort to containerPort for host-networked Pods. The raw summary and objectives both describe this Pod-specific defaulting as the core update, so the title matches the changeset.

Full details: Linked Issues check

Explanation

Issue #189 asks for C-0204 docs to stop saying containerPort-only and hostPort: 0 are allowed for host-networked Pods, and to check the C-0044 page. The diff removes the prior claim in the C-0204 page ("hostPort: 0 is treated as allowed") and adds text that the Kubernetes API server defaults omitted or zero hostPort to containerPort for regular and init containers when spec.hostNetwork is true. Both pages now state that a host-networked Pod with a nonzero containerPort is denied even when hostPort is omitted or 0, and that workload templates are evaluated before this Pod-specific default. The C-0044 page was updated to the same behavior. The docs are the only coding-adjacent artifacts in scope for this issue, and no code or automated test changes were required by the issue text. The claims match the defaulting behavior described in the issue context (#188). Minor residual uncertainty: the defaulting claim is documented, not verified in this review; the PR author reports server-side dry-run evidence.

Full details: Out of Scope Changes check

Explanation

The PR changes only two Markdown policy pages under docs/policies-based-on-kubescape-controls/. Every change concerns hostPort behavior for host-networked Pods, workload templates, or the C-0044/C-0204 comparison, which the issue asks to check and correct. The comparison text and the ephemeral-container and pods/ephemeralcontainers notes relate to the C-0044 check that #189 requires reviewing. The C-0044 change also adds a trailing newline at end of file, which is a trivial, related formatting edit. No unrelated files or code changes were found in the whole-PR diff against the merge base.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d726d172-0e00-4f6f-955c-96bf3cfb6c9e
Commits

Reviewing files that changed from the base of the PR and between f29cc53 and d61da83.

Files selected for processing: 2

  • docs/policies-based-on-kubescape-controls/kubescape-c-0044-deny-resources-with-host-port.md
  • docs/policies-based-on-kubescape-controls/kubescape-c-0204-deny-containers-using-host-ports.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@matthyx matthyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head d61da83 against main (74e4b2e; PR is 11 commits behind).

Verdict: request changes (one project-policy blocker; content itself looks correct).

Content check: The docs now match the policy YAML. C-0044 and C-0204 both deny a nonzero hostPort. For hostNetwork Pods they also deny a nonzero containerPort when hostPort is omitted or 0. Both check init containers. C-0204 additionally matches pods/ephemeralcontainers and includes ephemeral containers. This resolves #189. No duplicate or superseded PR found: #188 is the code change this follows, #134 and #140 are the related history, and none were rejected. The author has 3 open PRs (#205–#207), which is within the policy.

Blocker – Before/After proof missing (policy): The description lists what was verified but gives no before/after comparison using the same command and input. Please add, for example, the kubectl apply --dry-run=server -o yaml output for the same host-networked Pod and Deployment template showing hostPort defaulted on the Pod and unset on the template. Alternatively, show the previous C-0204 text claiming hostPort: 0 is allowed next to the corrected behavior.

CI: test-all-policies is red on d61da83, but the failure is unrelated to this docs-only diff. The failed tests are controls/C-0050 and the privileged runtime policy, and the base f29cc53 failed the same way (main-policy-automation run on that commit). The last three main runs are green. Please rebase onto main and get a green run. I did not approve any workflow runs or run tests locally.

Nonblocking: None to track.

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@ANAMASGARD
ANAMASGARD force-pushed the docs/hostnetwork-hostport-defaulting branch from d61da83 to 2af14b4 Compare December 2, 2026 10:20

@matthyx matthyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed head 2af14b4 against main (4bd6dec). The PR is rebased, the docs match the C-0044/C-0204 policy behavior (nonzero hostPort denied; host-networked Pods with a nonzero containerPort denied via API defaulting; templates not defaulted; C-0204 also covers ephemeral containers), and it resolves #189. The description now has Before/After proof, and main-policy-automation is green on this commit. No blockers. Not rerun: the kind admission cases after the rebase (docs-only diff).

@matthyx
matthyx merged commit aa21dc8 into kubescape:main Dec 2, 2026
7 checks passed
@matthyx matthyx moved this from Waiting on Author to To Archive in KS PRs tracking Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

docs: C-0204/C-0044 pages should mention hostNetwork Pod hostPort defaulting

2 participants